package com.jing21.learn.basic.api.controller;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.inject.Inject;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.Map;

/**
 * Created by 郑靖 on 2017/9/24.
 */
@RestController
@RequestMapping("/product")
public class ProductApiController {

    int count = 1;
    @Inject
    BeanFactory beanFactory;

    @GetMapping("/test")
    @org.springframework.cache.annotation.Cacheable(value = "product",keyGenerator = "productKeyGenerator")
    public String test(java.security.Principal principal) {

        SecurityContextHolder.getContext().getAuthentication();
        count++;
        return "test number is :" + count;
    }

    @GetMapping("/datetime")
    public Map<String, Object> product(java.security.Principal principal) {

        System.err.println("beanFactory is :" + beanFactory);
        return Collections.singletonMap("datetime", LocalDateTime.now());
    }
}
